import { assetsPageApi } from '@/api/asset-management/assets'
import { Ref } from 'vue'
import { PageRequest } from '@/api/types'
import { AssetsModel } from '@/api/model/assets-model'
import { userInfo } from '~/types/user'
import { userInfoModel } from '@/api/model/userModel'

type Props = {
  userInfo: Ref<userInfo<userInfoModel>>
}

export const useAssetsApi = ({ userInfo }: Props) => {
  // 获取台账列表
  const fetchAssetsPage = async (
    pageRequest: PageRequest,
    queryParams: AssetsModel
  ) => {
    const res = await assetsPageApi({
      ...queryParams,
      orgId: userInfo.value.orgId,
      pageRequest
    })

    if (res.code === '0000') {
      return {
        data: res.data?.content,
        total: res.data?.total
      }
    }
  }

  return {
    fetchAssetsPage
  }
}
